package mysql

import (
	"goods-guard/userrpc/userrpc"
	"gorm.io/gorm"
)

type Goods struct {
	gorm.Model
	UserId     int64   `gorm:"type:int(11);not null;comment:用户id"`
	GoodsName  string  `gorm:"type:varchar(30);not null;comment:商品名"`
	GoodsPrice float32 `gorm:"type:decimal(10,2);not null;comment:商品价格"`
	Address    string  `gorm:"type:varchar(30);not null;comment:供货地址"`
}

func (g *Goods) CreateGoods(db *gorm.DB) error {
	return db.Debug().Create(g).Error
}
func GoodsList(db *gorm.DB, id int64) []*userrpc.GoodsList {
	var list []*userrpc.GoodsList
	db.Debug().Model(&Goods{}).
		Select(
			"goods_name",
			"goods_price",
			"address",
			"user_id",
		).
		Where("goods.user_id=?", id).
		Find(&list)
	return list
}
